
package main;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ConectarBaseDatos {
       public  ResultSet rs;
    public  Connection con;
    public  Statement stmt;
    public  String driver;
    public  String conneccionString;
    public  String usuario;
    public  String clave;
     public boolean conectar()
    {
             driver = "org.postgresql.Driver";
             conneccionString = "jdbc:postgresql://localhost:5432/postgres";
             usuario = "postgres";
             clave = "fcbarcelona";
             
            try {
                Class.forName(driver);
                return true;
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(ConectarBaseDatos.class.getName()).log(Level.SEVERE, null, ex);
                return false;
            }
    }

    public void desconectar()
    {
        try {
            con.close();
        } catch (SQLException ex) {
            Logger.getLogger(ConectarBaseDatos.class.getName()).log(Level.SEVERE, null, ex);
        }
    }


    public boolean exec(String sql)
    {
        try {
            con = DriverManager.getConnection(conneccionString, usuario, clave);
            stmt = con.createStatement();
            rs = stmt.executeQuery(sql);
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(ConectarBaseDatos.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }

    }

    public String getClave() {
        return clave;
    }

    public void setClave(String clave) {
        this.clave = clave;
    }

    public Connection getCon() {
        return con;
    }

    public void setCon(Connection con) {
        this.con = con;
    }

    public String getConneccionString() {
        return conneccionString;
    }

    public void setConneccionString(String conneccionString) {
        this.conneccionString = conneccionString;
    }

    public String getDriver() {
        return driver;
    }

    public void setDriver(String driver) {
        this.driver = driver;
    }

    public ResultSet getRs() {
        return rs;
    }

    public void setRs(ResultSet rs) {
        this.rs = rs;
    }

    public Statement getStmt() {
        return stmt;
    }

    public void setStmt(Statement stmt) {
        this.stmt = stmt;
    }

    public String getUsuario() {
        return usuario;
    }

    public void setUsuario(String usuario) {
        this.usuario = usuario;
    }






}
